/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.oea.hibernate.entities;

import com.oea.hibernate.utilities.HibernateUtil;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import org.hibernate.Query;
import org.hibernate.Session;

/**
 *
 * @author Aspire Tech
 */
@Table(name = "faculties_subjects")
@Entity
public class Faculty_Subject extends AbstractEntity {

    @GeneratedValue
    @Column(name = "id")
    @Id
    protected Long id;

    @Column(name = "fid")
    protected Long fid;

    @Transient
    protected Faculty faculty;

    @Column(name = "bid")
    protected Long bid;

    @Column(name = "divid")
    protected Long divid;

    @Transient
    protected Branch branch;

    @Column(name = "semester")
    protected int semester;

    @Column(name = "subid")
    protected Long subid;

    @Column(name = "nooflectures")
    protected int nooflectures;

    @Column(name = "nooflabs")
    protected int nooflabs;

    @Transient
    protected Branch branch_obj;
    
     @Transient
    protected Division division;

    public Division getDivision() {
        return division;
    }

    public void setDivision() {
        this.division = (Division) new Division().getById(divid);
    }
     

    public Long getDivid() {
        return divid;
    }

    public void setDivid(Long divid) {
        this.divid = divid;
    }

    public Branch getBranch_obj() {
        return branch_obj;
    }

    public void setBranch_obj() {
        this.branch_obj = (Branch) new Branch().getById(this.bid);
    }

    public int getNooflectures() {
        return nooflectures;
    }

    public void setNooflectures(int nooflectures) {
        this.nooflectures = nooflectures;
    }

    public int getNooflabs() {
        return nooflabs;
    }

    public void setNooflabs(int nooflabs) {
        this.nooflabs = nooflabs;
    }

    @Transient
    protected Subject subject;

    public Subject getSubject() {
        return subject;
    }

    public void setSubject() {
        this.subject = (Subject) new Subject().getById(subid);
    }

    public Faculty getFaculty() {
        return faculty;
    }

    public void setFaculty() {
        this.faculty = (Faculty) new Faculty().getById(fid);
    }

    public Branch getBranch() {
        return branch;
    }

    public void setBranch() {
        this.branch = (Branch) new Branch().getById(bid);
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getFid() {
        return fid;
    }

    public void setFid(Long fid) {
        this.fid = fid;
    }

    public Long getBid() {
        return bid;
    }

    public void setBid(Long bid) {
        this.bid = bid;
    }

    public int getSemester() {
        return semester;
    }

    public void setSemester(int semester) {
        this.semester = semester;
    }

    public Long getSubid() {
        return subid;
    }

    public void setSubid(Long subid) {
        this.subid = subid;
    }

    public static List<Faculty_Subject> getAllSubjectForBranchAndSemester(Long brid, int semester) {
        List<Faculty_Subject> li = null;
        try {
            Session s = HibernateUtil.getSessionFactory().openSession();

            System.out.println("sql = from Faculty_Subject where bid=" + brid + " AND semester=" + semester);
            Query q = s.createQuery("from Faculty_Subject where bid='" + brid + "' AND semester=" + semester);

            li = q.list();
            System.out.println("Subject Arr Sizee=" + li.size());

        } catch (Exception e) {
            e.printStackTrace();
        }
        return li;
    }

    public static List<Faculty_Subject> getAllSubjectForFaculty(Long fid) {
        List<Faculty_Subject> li = null;
        try {
            Session s = HibernateUtil.getSessionFactory().openSession();

            Query q = s.createQuery("from Faculty_Subject where fid=" + fid);

            li = q.list();

        } catch (Exception e) {
            e.printStackTrace();
        }
        return li;
    }

    public static List<Faculty_Subject> getSubjectsOfFaculty(Long fid) {
        List<Faculty_Subject> list = null;
        Session ses = HibernateUtil.getSessionFactory().openSession();
        Query query = ses.createQuery("from Faculty_Subject where fid=" + fid);
        list = query.list();
        return list;
    }
    
    public static List<Faculty_Subject> getSubjectsOfFacultyForDivision(Long fid,Long divid) {
        List<Faculty_Subject> list = null;
        Session ses = HibernateUtil.getSessionFactory().openSession();
        Query query = ses.createQuery("from Faculty_Subject where fid=" + fid+" AND divid=" + divid);
        list = query.list();
        return list;
    }

    public static List<Faculty_Subject> getAllFacultiesForSubject(Long subid) {
        List<Faculty_Subject> li = null;
        try {
            Session s = HibernateUtil.getSessionFactory().openSession();

            Query q = s.createQuery("from Faculty_Subject where subid=" + subid);

            li = q.list();

        } catch (Exception e) {
            e.printStackTrace();
        }
        return li;
    }

    public static List<Faculty_Subject> getAllFacultiesForSubjectBySubAndDiv(Long subid,Long divid) {
        List<Faculty_Subject> li = null;
        try {
            Session s = HibernateUtil.getSessionFactory().openSession();

            Query q = s.createQuery("from Faculty_Subject where subid=" + subid +" AND divid=" + divid);

            li = q.list();

        } catch (Exception e) {
            e.printStackTrace();
        }
        return li;
    }
    
     public static List<Faculty_Subject> getAllSubjectForBranchAndSemesterAndDivision(Long brid, int semester,Long divid) {
        List<Faculty_Subject> li = null;
        try {
            Session s = HibernateUtil.getSessionFactory().openSession();

            System.out.println("sql = from Faculty_Subject where bid=" + brid + " AND semester=" + semester+ " AND divid=" + divid);
            Query q = s.createQuery("from Faculty_Subject where bid='" + brid + "' AND semester=" + semester+ " AND divid=" + divid);

            li = q.list();
            System.out.println("Subject Arr Sizee=" + li.size());

        } catch (Exception e) {
            e.printStackTrace();
        }
        return li;
    }

    

}
